home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / contkit.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  5KB  |  176 lines

  1. #include "contkit.h"
  2. #include "help.h"
  3.  
  4. ContextKit::ContextKit(char* HOT, rect STATUSPOS, int STATUSTYPE,
  5.            char** STATUSSTRINGS, int* STATUSLIST)
  6.     : Context(STATUSPOS, STATUSTYPE, STATUSSTRINGS, STATUSLIST)
  7.     {
  8.     hot = HOT;
  9.     }
  10. /////////////////////////////
  11. void ContextKit::exe(int )
  12.     {
  13.     int sub_action = 0;                            // reserv
  14.     while(1)
  15.     {
  16.     mouseShowCursor();
  17.     int res_cur = current;                     // reserv
  18.  
  19.     list[current]->exe(sub_action);    // event which can not be procecced
  20.     sub_action = 0;                        // with current object
  21.  
  22.     if(!current)                           // after pressing on 0th window
  23.         {                                  // - proceed with 1th
  24.         shift();
  25.         showStatus(1);
  26.         continue;
  27.         }
  28.  
  29.     if(global_i[0])            // if exe() sets action_type to global_i[0]
  30.         {
  31.         if(global_i[0] == AC_NEXT)             // command for objkit, not for any of its components
  32.         {                                  // usage: menu->find can not find the given string
  33.         moveTo(list[current]->isPoint());  // in the menu->itemList
  34.         showStatus(current);
  35.         sub_action = AC_NEXT;
  36.         continue;
  37.         }
  38.  
  39.         int res = current;                  // where to return whith ESC-like command
  40.         moveTo(list[current]->isPoint());
  41.         if(global_i[0] != AC_CANCEL)
  42.         showStatus(current);
  43.         global_num = 1;
  44.         list[current]->exe(global_i[0]); // for example: button->exe(), calls menu->exe()
  45.  
  46.             if(global_i[0] == AC_REDRAW || global_i[0] == AC_RESIZE
  47.             || global_i[0] == AC_MOVE)
  48.         {
  49.                 return;
  50.         }
  51.  
  52.         if(global_i[0] != AC_NEXT)  // return after execution, f.e. button - menu->exe(AC_LEFT) - again return to button
  53.         {
  54.         moveTo(get(list[res]));
  55.         showStatus(current);
  56.         global_num = 1;
  57.         if(list[current]->isRet(act_ret()))
  58.             {
  59.             if(global_i[0] != AC_NULL)         // if !CANCEL pressed
  60.             global_i[0] = action_type;
  61.             showStatus(used);
  62.             return;
  63.             }
  64.         }
  65.         }
  66.  
  67.     if(!global_i[0])
  68.         {
  69.         if(e.what == KEYEVENT)
  70.         {
  71.         char* ch;
  72.         if(hot != NULL
  73.             && (ch = strchr(strlwr(hot), e.keypress()))
  74.             && (e.key < 256) && e.keypress())
  75.             {
  76.             mouseHideCursor();
  77.             list[current]->show();
  78.             moveTo(ch - hot + 1);
  79.             showStatus(current);
  80.             mouseShowCursor();
  81.             continue;
  82.             }
  83.  
  84.         switch(e.key)
  85.             {
  86.             case EVENT_F1:
  87.             if(help_context)
  88.                 ::help(help_context);
  89.             break;
  90.             case EVENT_ALT_F3:
  91.             if(!isRet(RET_REMOVE))
  92.                 continue;
  93.             global_i[0] = AC_ERASE;
  94.             showStatus(used);
  95.             return;
  96.             case EVENT_ALT_F4:
  97. //            global_i[0] = AC_ERASE;
  98.             showStatus(used);
  99.             return;
  100.             case EVENT_F2:
  101.             case EVENT_RETURN:
  102.             if(list[current]->isRet(RET_REMOVE | RET_OK
  103.                         | RET_MOUSE))
  104.                 {
  105.                 global_i[0] = action_type;
  106.                             global_num = 1;
  107.                 showStatus(used);
  108.                 return;
  109.                 }
  110.             break;
  111.             case EVENT_TAB: mouseHideCursor(); shift();
  112.                 showStatus(current); mouseShowCursor(); break;
  113.             case EVENT_F6:
  114.             case EVENT_ALT_TAB:
  115.             case EVENT_F10:
  116.             case EVENT_ESC: global_i[0] = 0;
  117.             if(current != used)
  118.                 showStatus(used);
  119.             return;
  120.             default: break;
  121.             }
  122.         }
  123.         else
  124.         if(e.mouse1())    // mouse pressed
  125.             {
  126.             int n = 1;
  127.             if(!list[0]->mouse_in(e.where()))  // outside
  128.             {
  129.             global_i[0] = AC_CLOSE;
  130.             showStatus(used);
  131.             return;
  132.             } // mouse pressed outside
  133.             while(n != used + 1)   // where it was pressed?
  134.             {
  135.             if(list[current]->mouse_in(loc(e.where())))
  136.                 {
  137.                 if(res_cur == current
  138.                    && list[current]->isRet(RET_MOUSE))
  139.                 {
  140.                 global_i[0] = action_type;
  141.                 showStatus(used);
  142.                 return;
  143.                 }
  144.                 showStatus(current);
  145.                 break;
  146.                 }
  147.             mouseHideCursor();
  148.             shift();
  149.             mouseShowCursor();
  150.             n++;
  151.             }
  152.             if(n == used + 1)
  153.             {
  154.             current = 0;               // if background object pressed -
  155.             if(help_context)           // we check it last, and try
  156.                 ::help(help_context);  // to show help
  157.             }
  158.             }
  159.         }
  160.     }
  161.     }
  162. ////////////////////
  163. void ContextKit::show()
  164.     {
  165.     mouseHideCursor();
  166.     if(list[0] != 0)
  167.     list[0]->show();
  168.     for(int i = 1; i <= used; i++)   // attention !!!  0 - base window
  169.     list[i]->show();
  170.     moveTo(1);
  171.     showStatus(1);
  172.     mouseShowCursor();
  173.     }
  174. /////////////////////
  175.  
  176.